package com.zuo.seckilldemo.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

@Component
public class MD5Util {
    public static String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    private static final String salt = "13213xzc";

    public static String frontEndPassToBackEnd(String inputPass){
        String str = salt+inputPass;
        return md5(str);
    }

    public static String backEndPassToDB(String fromPass,String salt){
        String str = salt+fromPass;
        return md5(str);
    }

    public static String frontEndPassToDB(String inputPass,String salt){
        String backEndPass = frontEndPassToBackEnd(inputPass);
        String dbPass = backEndPassToDB(backEndPass, salt);
        return dbPass;
    }

//    public static void main(String[] args) {
//        //d6a280b51148090ccef1d92afdd0a4bb
//        System.out.println(frontEndPassToBackEnd("123456"));
//        //5164e5e499683ab8289a1541cceac010
//        System.out.println(backEndPassToDB("d6a280b51148090ccef1d92afdd0a4bb","13213xzc"));
//        //5164e5e499683ab8289a1541cceac010
//        System.out.println(frontEndPassToDB("123456","13213xzc"));
//    }
}
